#include <stdio.h>
#include <unistd.h>
#include <dirent.h>
#include <sys/types.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <cstring> 
#define BUFFER_SIZE 128
// 定义一个结构体FileInfo，用于存储文件信息
struct FileInfo
{
    FileInfo():name(""), fileSize(""), filePath(""), fileType(0) {}
    std::string name;
    std::string fileSize;
    std::string filePath;
    unsigned char fileType; 
};
// 定义一个递归函数musid，用于遍历目录
void musid(std::string path)
{
    DIR *dir = opendir(path.c_str());
    if(dir == NULL)
    {
        std::cout<<"open dir error"<<std::endl;
        return;
    }  
    dirent *ptr = nullptr;
    while((ptr =readdir(dir)) != nullptr)
    {
        std::string dname(ptr->d_name);
        if(dname != "." && dname !="..")
        {
            FileInfo *info = new FileInfo();
            info->name = dname;
            info->fileType = ptr->d_type;
            info->filePath = path + "/" + ptr->d_name;
            if(info->fileType == DT_DIR)//文件夹
            {
                musid(info->filePath);
            }
            else
            {
                if(strstr(ptr->d_name,".mp3"))
                {
                    std::cout<<ptr->d_name<<std::endl;
                }
            }

        }
    }
        closedir(dir);

}
int main()
{
    /*递归遍历文件夹*/
    musid(".");
    return 0;
}